﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MediaRecommender.Controller;
using MediaRecommender.Model;

namespace MediaRecommender
{
    public partial class CreateUser : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void SignUpButton_Click(object sender, ImageClickEventArgs e)
        {
            Sex gender = Sex.Male;
            DateTime birthday = Convert.ToDateTime(BirthdayTextBox.Text);
            bool checkIfUserCreated = false;

            if (PasswordTextbox.Text != PasswordCheckTextbox.Text)
                UserCheckLabel.Text = "Your Password doesn't match!";
            else
        {
                gender = (Sex)Enum.Parse(typeof(Sex), SexList.SelectedItem.Text);
            var dbWriter = new UserRegistrationController();
                try
                {
                    checkIfUserCreated = dbWriter.CheckIfUserIsValid(UserNameTextbox.Text, PasswordTextbox.Text, birthday, Model.Sex.Male, new List<int>());
                }
                catch (ArgumentException ex) { UserCheckLabel.Text = ex.Message; }

                if (checkIfUserCreated)
                Response.Redirect("Default.aspx");
            
        }
    }
}
}